{template 'common/header'}
<title>体验券设置</title>

<link href="../addons/ewei_shop/plugin/commission/template/mobile/default/static/datepicker/common.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../addons/ewei_shop/plugin/commission/template/mobile/default/static/datepicker/date.js" ></script>
<script type="text/javascript" src="../addons/ewei_shop/plugin/commission/template/mobile/default/static/datepicker/iscroll.js" ></script>
<script src="../addons/ewei_shop/static/js/dist/ajaxfileupload.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
	//$('#beginTime').date();
	$('#starttime').date({theme:"datetime"});
        $('#endtime').date({theme:"datetime"});
});
</script>
<style type="text/css">
    body {margin:0px; background:#efefef; font-family:'微软雅黑'; -moz-appearance:none;}
    a {text-decoration:none;}
    .myshop_addnav {height:44px; width:94%; padding:0 3%; border-bottom:1px solid #f0f0f0; border-top:1px solid #f0f0f0; margin-top:14px; line-height:42px; color:#666; background:#fff;}
    .myshop_addnav {height:40px; width:94%; padding:0 3%; border-bottom:1px solid #f0f0f0; border-top:1px solid #f0f0f0; margin-top:14px; line-height:40px; color:#666; }
.myshop_main {height:auto;width:94%; padding:0px 3%; border-bottom:1px solid #f0f0f0; border-top:1px solid #f0f0f0; margin-top:14px; background:#fff;}
.myshop_main .line {height:44px; width:100%; border-bottom:1px solid #f0f0f0; line-height:44px;}

.myshop_main .line .label { float:left;width:75px;font-size:14px;}
.myshop_main .line .info { float:right; width:100%; margin-left:-75px;text-align: right;overflow:hidden;height:44px;}
.myshop_main .line .info .inner { color:#666;margin-left:75px;}

.myshop_main .line1 {height:80px; width:100%; border-bottom:1px solid #f0f0f0; line-height:80px;}
.myshop_main .line1 .label { float:left;width:70px;}
.myshop_main .line1 .info { float:right; width:100%; margin-left:-75px;;overflow:hidden;height:80px;}
.myshop_main .line1 .info .inner { color:#666;margin-left:75px;padding-top:10px;}
.myshop_main .line1 .info .inner .plus { float:left;width:60px;height:60px;border:1px solid #efefef; color:#efefef;; font-size:45px;line-height:55px;text-align:center;}
.myshop_main .line1 .info .inner .plus1 { float:left;width:90%;height:60px;border:1px solid #efefef; color:#efefef;; font-size:45px;line-height:55px;text-align:center;}

.myshop_main .line1 .info .inner .preview0 { position:absolute; width:60px;height:60px;z-index:2}
.myshop_main .line1 .info .inner .preview1 { position:absolute; width:90%;height:60px;z-index:2}

.myshop_main .line1 .info .inner .preview0 img,.myshop_main .line1 .info .inner .preview1 img { width:100%;height:100%;}

.myshop_main .line input {float:left; height:44px; width:100%; padding:0px; margin:0px; border:0px; outline:none; font-size:16px; color:#666;padding-left:5px;}
.myshop_main .line select  {float:left; border:none;height:25px;width:100%;color:#666;font-size:16px;margin-top:10px;}
.myshop_sub1 {height:44px; width:94%; margin:14px 3% 0px; background:#ff4f4f; border-radius:4px; text-align:center; font-size:16px; line-height:44px; color:#fff;}
.myshop_sub2 {height:44px; width:94%; margin:14px 3% 0px; background:#ddd; border-radius:4px; text-align:center; font-size:16px; line-height:44px; color:#666; border:1px solid #d4d4d4;}

.myshop_main .line2 {width:100%;  line-height:25px; color:#666;overflow:hidden; font-size:13px;word-break: break-all;}

textarea {height:60px;line-height:22px; width:100%;padding:5px;font-size:13px; background:#fff; padding-left:2%; border:1px solid #e9e9e9; margin:14px 0px 0; -webkit-appearance: none;} 
.myshop_menu {height:44px; background:#fff;}
.myshop_menu .nav {height:44px; width:50%; border-bottom:1px solid #f1f1f1;background:#fff; border-left:1px solid #f1f1f1; float:left; line-height:44px; font-size:14px; color:#666; text-align:center;}
.myshop_menu .navon {height:42px; color:#ff771b; border-bottom:2px solid #ff771b;}

    .myshop_main .pic { border:1px solid #e9e9e9;width:100%;height:40px;border-radius:5px;color:#999;padding:3px;line-height:35px;font-size:13px;padding-left:10px;}
    .myshop_main .pic span {float:left;width:150px;}
    .myshop_main .pic .plus { float:right;width:30px;height:30px;border:1px solid #e9e9e9; color:#dedede;; font-size:18px;line-height:30px;text-align:center;}
    .myshop_main .pic .plus i { left:7px;top:7px;}
    .myshop_main .pic .images {float: right; width:auto;height:30px;}
    .myshop_main .pic .images .img { float:left; position:relative;width:30px;height:30px;border:1px solid #e9e9e9;margin-right:5px;}
    .myshop_main .pic .images .img img { position:absolute;top:0; width:100%;height:100%;}
    .myshop_main .pic .images .img .minus { position:absolute;color:red;width:8px;height:12px;top:-15px;right:-1px;}
.info2 {padding:10px;border-bottom:1px solid #eee; border-top:1px solid #eee;}
.info2 .con {height:auto; padding:10px 0px;}
.info2 .con .line2 {height:auto; overflow:hidden; margin-bottom:5px;}
.info2 .con .line2 .t1 {height:auto; width:55px; float:left; font-size:14px; color:#666; line-height:20px;}
.info2 .con .line2 .t2 {padding-left:0px; background:#f90;}
.info2 .con .line2 .t2 .t3 {height:auto; float:left; font-size:14px; color:#999;}
input.inputDate{width:120px;}
#dateshadow{height:150%;}
</style>
<div id='container'></div>
   <div class="page_topbar">
    <a href="javascript:;" class="back" onclick="location.href='{php echo $this->createPluginMobileUrl('commission/myshop/activity_list')}'"><i class="fa fa-angle-left"></i></a>
    <div class="title">编辑体验券</div>
</div>
<div id="datePlugin"></div>
    <div class="myshop_menu">
            <div class="nav navon" style="border-left:0px;width:49%;" onclick="location.href='{php echo $this->createPluginMobileUrl('commission/myshop',array('op'=>'experience'))}'">编辑体验券</div>
            <div class="nav"  onclick="location.href='{php echo $this->createPluginMobileUrl('commission/myshop',array('op'=>'experience_log'))}'">体验券记录</div>
    </div>
 <div class="myshop_main" data-ogid='0' >
        <div class="line1">
            <div class="label">样式图片</div>
            <div class="info">
                <div class="inner">
                    <div class="plus" style="position:relative;">
                        <input type="file" data-tag="0" name='imgFile0' id='imgFile0' style="position:absolute;left:0;z-index:3;width:60px;height:60px;-webkit-tap-highlight-color: transparent;filter:alpha(Opacity=0); opacity: 0;" />
                        <i class="fa fa-plus"  style="position:absolute;top:10px;right:12px;z-index:1"></i>
                        <div id="preview0" class="preview0">
                            <img src="{$info['image']}"/>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="line"><div class="label">体&nbsp;&nbsp;验&nbsp;&nbsp;店：</div><div class="info"><div class="inner"><input type="text" id="shopname" value="" placeholder="请输入10个以内的字数"/></div></div></div>
        <div class="line"><div class="label">体验项目：</div><div class="info"><div class="inner"><input type="text" id="title" value="" placeholder="请输入10个以内的字数"/></div></div></div>
        <div class="line"><div class="label">数&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;量：</div><div class="info"><div class="inner"><input type="text" id="num" value="" placeholder="请输入体验券数量"/></div></div></div>
        <div class="line"><div class="label">价&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;值：</div><div class="info"><div class="inner"><input type="text" id="money" value="" placeholder="请输入体验券价值"/></div></div></div>
        <div class="line"><div class="label">支付金额：</div><div class="info"><div class="inner"><input type="text"  id="cash"  placeholder="请输入要支付的金额"/></div></div></div>
        <div class="line"><div class="label">地&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;点：</div><div class="info"><div class="inner"><input type="text" id="address" value="" placeholder="请输入店铺的地址"/></div></div></div>
        <div class="line"><div class="label">开始时间：</div><div class="info"><div class="inner"><input type="text"  id="starttime" value="" /></div></div></div>
        <div class="line"><div class="label">结束时间：</div><div class="info"><div class="inner"><input  type="text" id="endtime" value=""  /></div></div></div>
        
        <!--<div class="line" style='border:none'> 
        <div class="pic">
            上传一张样式图片(640x300)
            <div class="plus" style="position:relative"><i class="fa fa-plus" style="position:absolute;"></i>
                <input type="file" name='imgFile0' id='imgFile0' style="position:absolute;width:30px;height:30px;-webkit-tap-highlight-color: transparent;filter:alpha(Opacity=0); opacity: 0;" />
            </div>
            <div class="images"></div>
        </div>
        </div>-->
    </div>
    <div class="myshop_sub1" id='disabled' style="background:#888888;">确认</div>
    <div class="myshop_sub1" id='myshop_submit' style="display:none;">确认</div>
    <div class="myshop_sub1" id='record' onclick="location.href='{php echo $this->createPluginMobileUrl('commission/myshop',array('op'=>'experience_all_record'))}'">查看领取记录</div>
	<div class="info2">
        <div class="con">
          <div class="line2">
          	<div class="t2">
            	<div class="t3">1.本券仅供体验店线下使用。</div>
          	</div>
          </div>
          <div class="line2">
          	<div class="t2">
            	<div class="t3">2.本券不可兑换现金，不找零。</div>
          	</div>
          </div>
          <div class="line2">
          	<div class="t2">
            	<div class="t3">3.本券在有效期内使用有效。</div>
          	</div>
          </div>
          <div class="line2">
          	<div class="t2">
            	<div class="t3">4.体验店拥有最终解释权。</div>
          	</div>
          </div>
  	    </div>
	</div>
<!--<script id="tpl_img" type="text/html">
    <div class='img' data-img='<%filename%>'>
       <input type="hidden" id="tupian" value="<%filename%>"/>
       <img src='<%url%>' />
       <div class='minus'><i class='fa fa-minus-circle'></i></div>
   </div>
</script>-->
<script id="tpl_img" type="text/html">
<input type="hidden" id="img0" value="<%filename%>" />
<img src='<%url%>' tag="<%tag%>" img='<%filename%>'/>
</script>
<script language="javascript">
    require(['tpl', 'core'], function(tpl, core) {
                        function checkForm(){
                        var inputs=$(":input");
                        for(var i=1;i<inputs.length-2;i++)   {  
                              if(inputs[i].value==""||inputs[i].value==null){
                              return false;
                              }  
                        }
                        }
                        function checkdate(){
                            var check=checkForm();
                            var num=$('#num').val();
                            var money=$('#money').val();
                            var cash=$('#cash').val();
                            if(check != false && num > 0 && !isNaN(num) && money > 0 && !isNaN(money) && cash >= 0 && !isNaN(cash)){
                            $("#disabled").hide();
                            $("#myshop_submit").show();
                            }else{
                            $("#disabled").show();
                            $("#myshop_submit").hide();
                            }
                        }
                        $('#shopname').unbind('keyup').keyup(function(){
                            checkdate();
                        });
                        $('#title').unbind('keyup').keyup(function(){
                            checkdate();
                        });
                        $('#num').unbind('keyup').keyup(function(){
                            checkdate();
                        });
                        $('#money').unbind('keyup').keyup(function(){
                            checkdate();
                        });
                        $('#cash').unbind('keyup').keyup(function(){
                            checkdate();
                        });
                        $('#starttime').unbind('keyup').keyup(function(){
                            checkdate();
                        });
                        $('#endtime').unbind('keyup').keyup(function(){
                            checkdate();
                        });
                        $('#address').unbind('keyup').keyup(function(){
                            checkdate();
                        });
                        $('#img0').unbind('keyup').keyup(function(){
                            checkdate();
                        });
                    $('.plus input').change(function(){
                        core.loading('正在上传');
                        var tag =$(this).data('tag');
                        $.ajaxFileUpload({
                            url: core.getUrl('util/uploader_experience'),
                            data: {file: "imgFile" + tag},
                            secureuri: false, 
                            fileElementId: 'imgFile'+ tag, 
                            dataType: 'json', 
                            success: function(res, status) {
                                core.removeLoading();
                                var obj = $(tpl('tpl_img', res));
                                $('.preview' + tag).html(obj);
                                $('#img' + tag).val( res.filename );
                            }, error: function(data, status, e) {
                                core.removeLoading();
                                core.tip.show('上传失败!');
                            }
                        });
                    });
                            $('#myshop_submit').click(function(){
                               if($(this).attr('saving')=='1'){
                                   return;
                               }
                                $(this).html('正在处理...').attr('saving',1);
                                if($('#shopname').isEmpty()){
                                    core.tip.show('请输入店铺名称!');
                                    return;
                                }
                                if($('#title').isEmpty()){
                                    core.tip.show('请输入体验项目名称!');
                                    return;
                                }
                                if($('#num').isEmpty()){
                                    core.tip.show('请输入体验券数量!');
                                    return;
                                }
                                var num=$('#num').val();
                                if(num < 0){
                                    core.tip.show('体验券数量请输入大于0的数字!');
                                    return;
                                }
                                if(isNaN(num)){
                                    core.tip.show('数量，请输入数字类型!');
                                    return;  
                                }
                                if($('#money').isEmpty()){
                                    core.tip.show('请输入价值!');
                                    return;
                                }
                                var money=$('#money').val();
                                if(money < 0){
                                    core.tip.show('价值请输入大于0的数字!');
                                    return;
                                }
                                if(isNaN(money)){
                                    core.tip.show('价值，请输入数字类型!');
                                    return;  
                                }
                                if($('#cash').isEmpty()){
                                    core.tip.show('请输入支付金额!');
                                    return;
                                }
                                var cash=$('#cash').val();
                                if(cash < 0){
                                    core.tip.show('价值请输入大于0的数字!');
                                    return;
                                }
                                if(isNaN(cash)){
                                    core.tip.show('支付金额，请输入数字类型!');
                                    return;  
                                }
                                if($('#starttime').isEmpty()){
                                    core.tip.show('请输入开始时间!');
                                    return;
                                }
                                if($('#endtime').isEmpty()){
                                    core.tip.show('请输入结束时间!');
                                    return;
                                }
                                if($('#address').isEmpty()){
                                    core.tip.show('请输入店铺地点!');
                                    return;
                                }
                                if($('#img0').isEmpty()){
                                    core.tip.show('请上传图片!');
                                    return;
                                }
                                var data = {
                                        shopname: $('#shopname').val(),
                                        title: $('#title').val(),
                                        num: $('#num').val(),
                                        money: $('#money').val(),
                                        cash:$('#cash').val(),
                                        starttime: $('#starttime').val(),
                                        endtime: $('#endtime').val(),
                                        address: $('#address').val(),
                                        tupian: $('#img0').val()
                                }
                                core.pjson('commission/myshop',{
                                    op:'experience',
                                    data:data
                                 },function(postjson){
                                     if(postjson.status==1){
                                        location.href ='{php echo $this->createMobileUrl('experience/list')}&experienceid='+postjson.result.experienceid;
                                     }
                                     else{
                                         $(this).html('确认').removeAttr('saving');
                                          core.tip.show(postjson.result);
                                     }
                                },true,true);
                           }); 
    })
</script>
{template 'common/footer'}